
var app=getApp();
Page({
  /**
   * 页面的初始数据
   */
  data: {
    manageset:0,
    navbar:["资料修改","公司宣传","设置"],
    abouts: "",
    currentTab:0,
    isTeach:0,
    isTransmission:0,
    picId: "",
    companyId:"",
    companyName: "",
    companyAddress: "",
    telephoneNumber: "",
    belongIndustry: "",
    companyDesc: ""
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var id = options.companyId;
    var index = options.index;
    this.setData({
      currentTab: index==null?0:index,
    });
    var url = app.globalData.serverAddress + "/api/company/oneByid?id="+id+"&_t=" + new Date().getTime();
    app.httpPost(url, id).then((res)=>{
      if (res.data.flag){
        var company = res.data.company;
        var abouts = res.data.abouts;
        this.setData({
          abouts: abouts,
          picId: company.picId,
          companyId: company.id,
          companyName: company.companyName,
          companyAddress: company.companyAddress,
          telephoneNumber: company.telephoneNumber,
          belongIndustry: company.belongIndustry,
          companyDesc: company.companyDesc,
          isTeach:company.isTeach,
          isTransmission:company.isTransmission
        });
      }else{
      }
    }).catch((errMsg) => {
      console.log(errMsg); //错误提示信息
      wx.showModal({
        content: '网络异常',
        showCancel: false,
      })
    });
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  },

  //点击导航事件
  navbar_select: function(e){
    var index = e.currentTarget.dataset.idx;
    this.setData({
      currentTab: index
    });
  },
  //点击技能培训和产品宣传实现效果
  checkbox_change:function(e){
    var id=e.currentTarget.dataset.id;
    var teach = this.data.isTeach == 0 ? 1 : 0;
    var transmission = this.data.isTransmission == 0 ? 1 : 0;
    if (id =="isTeach"){
      this.setData({
        isTeach: teach
      });
    }
    if (id == "isTransmission"){
      this.setData({
        isTransmission: transmission
      });
    }
  },
  //修改资料提交表单
  companyinfo: function(e){
    var data = e.detail.value;
    console.log(data);
    var url = app.globalData.serverAddress + "/api/company/update?_t=" + new Date().getTime();
    app.httpPost(url, data).then((res)=>{
      if(res.data.flag){
        console.log("修改成功!");
      }else{
        console.log("返回了false");
      }
    }).catch((errMsg) => {
      console.log(errMsg); //错误提示信息
      wx.showModal({
        content: '网络异常',
        showCancel: false,
      })
    });
  },
  //input绑定输入的值事件
  inputValue: function (e) {
    var name = e.currentTarget.dataset.name;
    this.setData({
      [name]: e.detail.value
    });
  },
  /**
   * 跳转新增风采
   */
  drumbeating_insert: function(){
    wx.navigateTo({
      url: "/pages/company/about-card/about-card?companyId="+this.data.companyId+"&_t="+new Date().getTime()
    });
  },
  /**
   * 企业管理人你设置
   */
  kindToggle: function(){
    var tf = this.data.manageset;
    var result=tf==0?1:0;
    this.setData({
      manageset:result
    });
    //wx.reportAnalytics('click_view_programmatically', {})
  }
})